<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/9/10
 * Time: 10:43
 */

namespace Article\Controller;
use Think\Controller;

class IndexController extends Controller {
    public function _initialize(){
        header('Access-Control-Allow-Origin:*');
        header('Access-Control-Allow-Methods:GET');
        header('Access-Control-Allow-Methods:POST');
        header('Access-Control-Allow-Headers:x-requested-with,content-type');
    }

    public function index(){
        $id = $_GET["psid"];
        $data=M('article')->where(array('ps_id'=>$id))->select();
        $data[0]['readtimes']++;
        $info=array(
            'readtimes'=>$data[0]['readtimes']
        );
        M('article')->where(array('ps_id'=>$id))->save($info);
        $articleclass = new ArticleController();
        $article = json_decode($articleclass->getarticle($id),true);
        //echo $articleclass->getarticle($id);
        if($article["code"] == -1)
            $this->error();
        else
        {
            $this->assign("title",$article["value"]["title"]);
            $this->assign("author",$article["value"]["author"]);
            $this->assign("content",$article["value"]["content"]);
            $this->assign("time",$article["value"]["time"]);
            $this->display();
        }
    }

    public function error(){
        $this->display('error');
    }

    /**
     * 获取用户问题反馈
     */
    public function getQuestionFeedback(){
        $data = [
            'content'=>I('content'),
            'email'=>I('email'),
            'grade'=>empty(I('grade')) ? 0 : I('grade'),
            'token'=>I('token'),
            'create_time'=>time(),
        ];
        //内容不能为空
        if(empty(I('content'))){
            $result = ['status'=>0];
        }else{
            if(M('question_feedback')->add($data)){
                $result = ['status'=>1];
            }else{
                $result = ['status'=>0];
            }
        }
        $this->ajaxReturn($result);
    }





}